package tutorial.java.swing;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class TextfieldDemo extends JFrame implements ActionListener{
	private JTextField textfield;
	private JButton bHit;
	
	public TextfieldDemo(){
		super("Textfiel Demo");
		setSize(500,400);
//		setVisible(true);
		setResizable(false);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		textfield = new JTextField();
		add(textfield, "North", 0);
		
		bHit = new JButton("Click here");
		add(bHit, "South", 0);
		bHit.addActionListener(this);
	}
	
	public static void main(String[] args){
		TextfieldDemo textfielDemo = new TextfieldDemo();
		textfielDemo.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if ((JButton) e.getSource() == bHit) {
//			textfield.setText("Hai Love Oanh");
			JOptionPane.showMessageDialog(null, textfield.getText());
		}
	}
}
